package com.example.demo.exception;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by Administrator on 2017/10/31 0031.
 */
public class I18NProperties {

    private static I18NProperties il8n = new I18NProperties();
    private static Properties props;

    private I18NProperties() {
        props = new Properties();
        Resource resource = new ClassPathResource("i18n_spring_boot_zh.properties");
        try {
            props = PropertiesLoaderUtils.loadProperties(resource);
        } catch (IOException e) {

        }
    }

    public static I18NProperties getInstance() {
        return il8n;
    }

    public String getMsg(int code) {
        Object object = props.get(String.valueOf(code));
        return null == object ? null : object.toString().trim();
    }
}


